package metricsdata;

import java.util.ArrayList;


public class IntegerValueMetric extends AbstractMetricAttribute {

	private Integer value;
	
	/**
	 * Constructor of a DoubleValueMetric
	 * @param value
	 * 		the value of the metric (as Double)
	 * @param idOfMetricNamesInterface
	 * 		the id/nr of that metric in @MetricNamesInterface
	 */
	public IntegerValueMetric(Integer value, String shortcut, String fullName, String description) {
		
		super(shortcut,fullName,description);
		
		this.value = value;
	}
	
	/**
	 * Constructor of a DoubleValueMetric
	 * @param value
	 * 		the value of the metric (as String)
	 * @param idOfMetricNamesInterface
	 * 		the id/nr of that metric in @MetricNamesInterface
	 */
	public IntegerValueMetric(String value, String shortcut, String fullName, String description){
		
		super(shortcut,fullName,description);
		
		//Hack for old metrics
		if(value.contains(".")){
			this.value = (new Double(value)).intValue();
		}
		else{
			try{
				this.value = new Integer(value);
			}
			catch(NumberFormatException e){
				System.err.println("IntegerValueMetric ("+shortcut+") NumberFormatException for: "+value);
			}
		}
		
	}
	
	@Override
	public Integer getValue(){
		return value;
	}
	
	
	@Override
	public Integer getAvgValue() {
		return value;
	}

	@Override
	public Integer getFirstValue() {
		return value;
	}

	@Override
	public Integer getItemCount() {
		return 1;
	}

	@Override
	public Integer getMaxValue() {
		return value;
	}

	@Override
	public Integer getMinValue() {
		return value;
	}

	@Override
	public Integer getSumValue() {
		return value;
	}

	@Override
	public String toDatabaseString() {
		return value.toString();
	}

}
